package com.ktjy.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TimeSpanAspect {
    private static final Logger log = LoggerFactory.getLogger(TimeSpanAspect.class);

    public Object around(ProceedingJoinPoint jp) throws Throwable {
        log.info("开始之间." + jp.getSignature().getName());

        long startTime = System.currentTimeMillis();

        try {
            Object result = jp.proceed();
            log.info("结果." + jp.getSignature().getName(),result);
            return result;
        }catch (Throwable e) {
            log.info("异常信息."+jp.getSignature().getName(),e.getMessage());
            throw e;
        }finally {
            long endTime = System.currentTimeMillis();
            log.info("计算耗时" + jp.getSignature().getName(),(endTime-startTime));
        }
    }
}
